/*
 * @Author: HX
 * @Date: 2024-12-16 17:08:56
 * @LastEditors: yuanweijiang
 * @LastEditTime: 2025-02-06 10:42:54
 */
// 相机跟踪实体
import { viewFollowUAV } from '../modules/uva_handle.js';

export const TrackedEntity = {
	add(entity) {
		if (entity) {
			const cameraController = window.viewer.scene.mainCamera.cameraController();
			viewFollowUAV(entity);
			// 定义事件监听器
			window.viewer.addEventListener('update', (dt) => {
				// 获取实体的位置
				let destination = entity.transform.position.toCartesian3();
				// 设置相机基础位置
				let nowHeading = cameraController.heading;
				let nowPitch = cameraController.pitch;
				let nowRoll = cameraController.roll;
				cameraController.setView(destination, nowHeading, nowPitch, nowRoll);
				cameraController.moveBackward(2); //空间距离
				// 相机位置做偏移
				let distance = cameraController.positionWC.distance(entity.transform.position); //当前视角到中心点距离
				console.log('distance', distance);
				cameraController.moveBackward(distance); //空间距离
			});
		}
	},
	remove() {
		window.viewer.addEventListener('update');
	},
};
